#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：back 
@File    ：message_dao.py
@IDE     ：PyCharm 
@Author  ：七分是你
@Date    ：2024/6/29 下午2:14 
@explain : 
"""
import time

from app.dao.models import XlxMessage
from .base_dao import getDatabaseSession


class MessageOperateDao(object):
    @classmethod
    def send_message(cls, uid, content, types, inner_link='', inner_link_params=0, url_params=''):
        uid = uid if isinstance(uid, list) else [uid]
        setsqlarr = []
        timestamp = int(time.time())
        for value in uid:
            data = {'uid': value, 'type': types, 'content': content, 'inner_link': inner_link,
                    'inner_link_params': inner_link_params, 'addtime': timestamp, 'is_readed': 0,
                    'spe_link_params': url_params}
            setsqlarr.append(data)
        if setsqlarr:
            with getDatabaseSession() as session:
                log = [XlxMessage(**inset_data) for inset_data in setsqlarr]
                session.add_all(log)
        return
